package com.wcarmon.life.command{

    import com.adobe.cairngorm.commands.ICommand
    import com.adobe.cairngorm.control.CairngormEvent;
	import mx.controls.Alert;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.IResponder;
	import com.wcarmon.life.model.LifeModelLocator;
	import com.wcarmon.life.event.*;
	import com.wcarmon.life.business.*;
	import com.wcarmon.life.vo.*;
	import mx.utils.ObjectUtil;
	
	
	public class UpdateDashboardBlocksCommand implements ICommand, IResponder {
		include "../../includes/loggerSnippet.as";
		
		public function execute( event : CairngormEvent ) : void { 
			var delegate : UpdateDashboardBlocksDelegate = new UpdateDashboardBlocksDelegate(this);
			delegate.update();
		}
	
	 	public function result( event : Object ) : void {
			var e : ResultEvent = ResultEvent(event);
			var model : LifeModelLocator = LifeModelLocator.getInstance();
			model.dashboardSummaryBlocks = makeSummaryBlocks(e.result);
		}
	
		public function fault( event : Object ) : void {
			include "includes/FaultSnippet.as";
		}
		
		private function makeSummaryBlocks( o : Object ) : DashboardVO {
			var dvo : DashboardVO = new DashboardVO();
			
			dvo.overdueProjects = o.overdueProjects;
			dvo.overdueWFs = o.overdueWFs;
			dvo.overdueNAs = o.overdueNAs;
			dvo.projectsDueThisWeek = o.projectsDueThisWeek;
			dvo.NAsDueThisWeek = o.NAsDueThisWeek;
			dvo.oldestNAs = o.oldestNAs;
			return dvo;	
		}
	}
}